package com.gitee.itembucket.util.germ

import com.germ.germplugin.api.dynamic.gui.GermGuiEntity
import com.germ.germplugin.api.dynamic.gui.GermGuiLabel
import com.gitee.itembucket.util.germ.germ.GermPartDSL
import org.bukkit.entity.Entity
import taboolib.library.configuration.ConfigurationSection

class GermEntityDSL : GermPartDSL<GermGuiEntity>() {

    override val type = "entity"

    var tooltip = mutableListOf<String>()
    var entityName = "name"
    var model = ""
    var lookAtX: String? = null
    var lookAtY: String? = null
    var rotateY: String? = null
    var size = ""
    var entity: Entity? = null
    var entityId: Int = 0

    var width = ""
    var height = ""
    var followCursor = false

    override fun infuse(config: ConfigurationSection) {
        name = config.name

        config.getString("locationX")?.let { locationX = it }
        config.getString("locationY")?.let { locationY = it }
        config.getString("locationZ")?.let { locationZ = it }
        config.getString("entityName")?.let { entityName = it }
        config.getString("model")?.let { model = it }
        config.getString("lookAtX")?.let { lookAtX = it }
        config.getString("lookAtY")?.let { lookAtY = it }
        config.getString("rotateY")?.let { rotateY = it }
        config.getString("size")?.let { size = it }
        config.getString("width")?.let { width = it }
        config.getString("height")?.let { height = it }

        tooltip += config.getStringList("tooltip")
        followCursor = config.getBoolean("followCursor")
        enable = config.getBoolean("enable")
    }

    override fun create(): GermGuiEntity {
        return GermGuiEntity(name).also {
            it.enable = enable
            it.locationX = locationX
            it.locationY = locationY
            it.locationZ = locationZ

            it.width = width
            it.height = height
            it.size = size
            it.tooltip = tooltip
            it.isFollowCursor = followCursor
            it.rotateY = rotateY
            it.lookAtY = lookAtY
            it.lookAtX = lookAtX
            it.model = model
            if (entityId != 0) {
                it.setEntityFromId(entityId)
            }
            entity?.apply { it.entity = this }
        }
    }

}